package highTech.Thread;

public class TraditionalThreadSynchronized {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		final Output output=new Output();//��֤������ͬһ��
		new Thread(new Runnable() {
			@Override
			public void run() {
				while(true){
					try {
						Thread.sleep(100);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					output.print2("zhaohuizhaohui");
				}
			}
		}).start();
		
		new Thread(new Runnable() {
			@Override
			public void run() {
				while(true){
					try {
						Thread.sleep(100);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					output.print("linanlinan");
				}
			}
		}).start();
	}
}

class Output{
	public void print(String name){
		synchronized(this){//this��ʾ���õ�ǰ�����Ķ���������ͬһ�����󣬱�֤��ͬһ����
			for(int i=0;i<name.length();i++){
				System.out.print(name.charAt(i));
			}
			System.out.println();
		}
	}
	
	public synchronized void print2(String name){//�����ϼ�synchronized�õ�����ǵ�ǰ����
		for(int i=0;i<name.length();i++){
			System.out.print(name.charAt(i));
		}
		System.out.println();
	}
	
	public static void print3(String name){//�����ϼ�synchronized�õ�����ǵ�ǰ����
		for(int i=0;i<name.length();i++){
			System.out.print(name.charAt(i));
		}
		System.out.println();
	}
}
